package com.xique.door.service.impl;

import java.util.List;

import cn.hutool.core.collection.CollectionUtil;
import com.xique.common.core.text.Convert;
import com.xique.common.core.utils.DateUtils;
import com.xique.door.bean.domain.CardDevice;
import com.xique.door.bean.request.card.CardCommandSearchRequest;
import com.xique.door.bean.vo.card.CardCommandVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xique.door.mapper.DCardDeviceMapper;
import com.xique.door.service.IDCardDeviceService;

/**
 * deviceService业务层处理
 *
 * @author caogq
 * @date 2022-02-26
 */
@Service
public class DCardDeviceServiceImpl implements IDCardDeviceService
{
    @Autowired
    private DCardDeviceMapper dCardDeviceMapper;

    /**
     * 查询device
     *
     * @param id deviceID
     * @return device
     */
    @Override
    public CardDevice selectDCardDeviceById(Long id)
    {
        return dCardDeviceMapper.selectDCardDeviceById(id);
    }

    /**
     * 查询device列表
     *
     * @param cardDevice device
     * @return device
     */
    @Override
    public List<CardDevice> selectDCardDeviceList(CardDevice cardDevice)
    {
        return dCardDeviceMapper.selectDCardDeviceList(cardDevice);
    }

    /**
     * 新增device
     *
     * @param cardDevice device
     * @return 结果
     */
    @Override
    public int insertDCardDevice(CardDevice cardDevice)
    {
        cardDevice.setCreateTime(DateUtils.getNowDate());
        cardDevice.setUpdateTime(DateUtils.getNowDate());
        return dCardDeviceMapper.insertDCardDevice(cardDevice);
    }

    /**
     * 修改device
     *
     * @param cardDevice device
     * @return 结果
     */
    @Override
    public int updateDCardDevice(CardDevice cardDevice)
    {
        cardDevice.setUpdateTime(DateUtils.getNowDate());
        return dCardDeviceMapper.updateDCardDevice(cardDevice);
    }

    /**
     * 删除device对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteDCardDeviceByIds(String ids)
    {
        return dCardDeviceMapper.deleteDCardDeviceByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除device信息
     *
     * @param id deviceID
     * @return 结果
     */
    @Override
    public int deleteDCardDeviceById(Long id)
    {
        return dCardDeviceMapper.deleteDCardDeviceById(id);
    }

    @Override
    public int deleteDCardDeviceByIds(List<Long> ids){
        if (CollectionUtil.isEmpty(ids)) {
            return 1;
        }
       return   dCardDeviceMapper.deleteDCardDeviceByIdLists(ids);
    }

    @Override
    public int batchUpdateCardDevice(List<CardDevice> cardDevices) {
        return dCardDeviceMapper.batchUpdateCardDevice(cardDevices);
    }

    @Override
    public int batchInsertCardDevices(List<CardDevice> cardDevices) {
        if (CollectionUtil.isEmpty(cardDevices)) {
            return 1;
        }
        return dCardDeviceMapper.batchInsertCardDevices(cardDevices);
    }

    @Override
    public List<CardCommandVo> selectCardCommandList(CardCommandSearchRequest request) {
        return dCardDeviceMapper.selectCardCommandList(request);
    }

}
